/*
 * @Descripttion: 自定义工具类
 * @Author: 银河以北
 * @Date: 2021-09-26 22:17:42
 * @LastEditors: 银河以北
 * @LastEditTime: 2021-09-29 21:49:03
 */

import baseSetting from '@/config/defaultSettings' // 引入图片基本访问路径

/**
 * @Description: 处理图片路径工具函数
 * @Author: 银河以北
 * @Date: 2021-06-01 14:30:35
 * @param {*} url 图片路径 
 * @return {*}
 */
export function imgUrl(url: string): any {
    //判断是否是本地图片
    if (!url) return require('@/assets/img/emptyData/img_empty.png')

    // 判断图片链接是否为网络图片或base64
    if (url.substring(0, 4) === 'http' || url.substring(0, 10) === 'data:image') {
        // 网络图片或base64直接返回URL

        return url
    } else {
        // 非网络图片则拼接服务器BASE_URL
        return baseSetting.baseImgUrl + url
    }
}

/**
 * 获取当前标准时间格式
 * @returns 
 */
export function getStandardTime(): string {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month: number | string = date.getMonth() + 1;
    var strDate: number | string = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;


}